#ifndef DOODLEPAD_H
#define DOODLEPAD_H


#include <QtGui>
#include <QGLViewer/qglviewer.h>
using namespace qglviewer;

class Viewer;

class DoodlePad
{
 public :
  DoodlePad(Viewer*);
  ~DoodlePad();

  float *depthMap();
  QImage doodleImage();
  QList<QPolygon> polylines();

  int tag();
  int thickness();
  bool paintArea();

  bool firstTime();
  bool active();
  void resetFirstTime();

  bool doodleMenuActive();

  bool processKey(QKeyEvent*);

  void activate();
  void deactivate();
  void newPolyline();
  void addPoint(QPoint);
  void drawDoodle(QSize);
  void clearDoodleImage();

  bool mousePressEvent(QMouseEvent*);
  bool mouseMoveEvent(QMouseEvent*);

 private :
  Viewer *m_Viewer;

  int m_width, m_height;

  uchar* m_image;
  float* m_depthMap;
  QImage m_doodleImage;
  QImage m_gradImage;

  QRect m_selectImageRect;
  QImage m_selectImage;

  float m_depthScale;
  float m_depthShift;

  QList<QPolygon> m_polylines;

  bool m_active;
  bool m_firstTime;

  int m_prevMouseX, m_prevMouseY;
  
  void generateImage();
  void generateGradImage();
  QPolygon getPolygon(int, int);
  QImage getImage(int, int, QRect&);
  void addImage(QRect, QImage);
  bool removeImage(QRect, QImage);
};


#endif
